package com.dingup.api.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wancheng on 2018/8/15.
 */
public enum ExamTypeEnum {

    TOEFL("托福"),
    IELTS("雅思"),
    SAT("SAT"),
    ACT("ACT"),
    SSAT("SSAT"),
    TOEFLPRIMARY("小托福"),
    BANDFOUR("四级"),
    BANDSIX("六级"),
    COLLEGE("高考"),
    POSTGRADUATE("考研"),
    OTHER("其他"),

    LISTEN("听力"),
    SPEAK("口语"),
    READ("阅读"),
    WRITE("写作"),
    MATHEMATICS("数学"),
    GRAMMAR("语法"),
    SCIENCE("科学"),
    VOCABULARY("词汇"),
    TOTALSCORE("总分"),
    OTHERSUBJECT("其他课时"),
    DEFINESELF("自定义科目");
    private static final Integer ONE = 1;

    private static final Integer TWO = 2;

    private static final Integer THREE = 3;

    private static final Integer FOUR = 4;
    private String description;
    ;

    ExamTypeEnum(String description) {
        this.description = description;
    }

    ;

    public static Map<String, String> getMap(String name) {
        Map<String,String> map = new HashMap<>();
        for (ExamTypeEnum e : ExamTypeEnum.values()){
            if(e.name().equals(name)){
                map.put("name_en",e.name());
                map.put("name_ch",e.description);
                break;
            }
        }
        return map;
    }

    public static ExamTypeEnum getEnumByDescription(String description) {
        ExamTypeEnum examTypeEnum = null;
        for (ExamTypeEnum e : ExamTypeEnum.values()){
            if(e.description.equals(description)){
                examTypeEnum = e;
                break;
            }
        }
        return examTypeEnum;
    }

    public static List<Map<String, Object>> getAllExam() {
        List<Map<String, Object>> list = new ArrayList<>();
        list.add(enumToMap(TOEFL));
        list.add(enumToMap(IELTS));
        list.add(enumToMap(SAT));
        list.add(enumToMap(ACT));
        list.add(enumToMap(SSAT));
        list.add(enumToMap(TOEFLPRIMARY));
        list.add(enumToMap(BANDFOUR));
        list.add(enumToMap(BANDSIX));
        list.add(enumToMap(COLLEGE));
        list.add(enumToMap(POSTGRADUATE));
        list.add(enumToMap(OTHER));
        return list;
    }

    public static List<Map<String, Object>> getAllExamType(Boolean flag) {
        List<Map<String, Object>> list = new ArrayList<>();
        list.add(getToefl(flag));
        list.add(getIelts(flag));
        list.add(getSat(flag));
        list.add(getAct(flag));
        list.add(getSsat(flag));
        list.add(getToeflprimary(flag));
        list.add(getBandfour(flag));
        list.add(getBandsix(flag));
        list.add(getCollege(flag));
        list.add(getPostgraduate(flag));
        if(!flag){
            list.add(getOther(flag));
        }
        return list;
    }

    public static Map<String, Object> getToefl(Boolean flag) {
        List<Map<String, Object>> subject = new ArrayList<>();
        Map<String, Object> map = enumToMap(TOEFL);
        if(flag){
            subject.add(enumToMap(TOTALSCORE));
        }
        subject.add(enumToMap(LISTEN));
        subject.add(enumToMap(SPEAK));
        subject.add(enumToMap(READ));
        subject.add(enumToMap(WRITE));
        map.put("subject", subject);
        return map;
    }

    public static Map<String, Object> getIelts(Boolean flag) {
        Map<String, Object> map = enumToMap(IELTS);
        List<Map<String, Object>> subject = new ArrayList<>();
        if(flag){
            subject.add(enumToMap(TOTALSCORE));
        }
        subject.add(enumToMap(LISTEN));
        subject.add(enumToMap(SPEAK));
        subject.add(enumToMap(READ));
        subject.add(enumToMap(WRITE));
        map.put("subject", subject);
        return map;
    }

    public static Map<String, Object> getSat(Boolean flag) {
        Map<String, Object> map = enumToMap(SAT);
        List<Map<String, Object>> subject = new ArrayList<>();
        if(flag){
            subject.add(enumToMap(TOTALSCORE));
        }
        subject.add(enumToMap(READ));
        subject.add(enumToMap(WRITE));
        subject.add(enumToMap(GRAMMAR));
        subject.add(enumToMap(MATHEMATICS));
        map.put("subject", subject);
        return map;
    }

    public static Map<String,Object> getSsat(Boolean flag){
        Map<String,Object> map = enumToMap(SSAT);
        List<Map<String, Object>> subject = new ArrayList<>();
        if(flag){
            subject.add(enumToMap(TOTALSCORE));
        }
        subject.add(enumToMap(READ));
        subject.add(enumToMap(WRITE));
        subject.add(enumToMap(GRAMMAR));
        subject.add(enumToMap(MATHEMATICS));
        map.put("subject", subject);
        return map;
    }

    public static Map<String,Object> getToeflprimary(Boolean flag){
        Map<String,Object> map = enumToMap(TOEFLPRIMARY);
        List<Map<String, Object>> subject = new ArrayList<>();
        if(flag){
            subject.add(enumToMap(TOTALSCORE));
        }
        subject.add(enumToMap(READ));
        subject.add(enumToMap(WRITE));
        subject.add(enumToMap(SPEAK));
        map.put("subject", subject);

        return map;
    }

    public static Map<String,Object> getAct(Boolean flag){
        Map<String,Object> map = enumToMap(ACT);
        List<Map<String, Object>> subject = new ArrayList<>();
        if(flag){
            subject.add(enumToMap(TOTALSCORE));
        }
        subject.add(enumToMap(READ));
        subject.add(enumToMap(WRITE));
        subject.add(enumToMap(GRAMMAR));
        subject.add(enumToMap(MATHEMATICS));
        subject.add(enumToMap(SCIENCE));
        map.put("subject", subject);
        return map;
    }

    public static Map<String,Object> getBandfour(Boolean flag){
        Map<String,Object> map = enumToMap(BANDFOUR);
        List<Map<String, Object>> subject = new ArrayList<>();
        if(flag){
            subject.add(enumToMap(TOTALSCORE));
        }
        map.put("subject", subject);
        return map;
    }

    public static Map<String,Object> getBandsix(Boolean flag){
        Map<String,Object> map = enumToMap(BANDSIX);
        List<Map<String, Object>> subject = new ArrayList<>();
        if(flag){
            subject.add(enumToMap(TOTALSCORE));
        }
        map.put("subject", subject);
        return map;
    }

    public static Map<String,Object> getCollege(Boolean flag){
        Map<String,Object> map = enumToMap(COLLEGE);
        List<Map<String, Object>> subject = new ArrayList<>();
        if(flag){
            subject.add(enumToMap(TOTALSCORE));
        }
        map.put("subject", subject);
        return map;
    }

    public static Map<String,Object> getPostgraduate(Boolean flag){
        Map<String,Object> map = enumToMap(POSTGRADUATE);
        List<Map<String, Object>> subject = new ArrayList<>();
        if(flag){
            subject.add(enumToMap(TOTALSCORE));
        }
        map.put("subject", subject);
        return map;
    }

    public static Map<String,Object> getOther(Boolean flag){
        if (!flag){
            Map<String,Object> map = enumToMap(OTHER);
            List<Map<String, Object>> subject = new ArrayList<>();
            map.put("subject", subject);
            return map;
        }
        return null;
    }

    private static Map<String, Object> enumToMap(ExamTypeEnum e,Integer order) {
        Map<String, Object> map = new HashMap<>();
        map.put("name_ch", e.description);
        map.put("name_en", e.name());
        map.put("value", "");
        map.put("order", order);
        return map;
    }

    private static Map<String, Object> enumToMap(ExamTypeEnum e) {
        Map<String, Object> map = new HashMap<>();
        map.put("name_ch", e.description);
        map.put("name_en", e.name());
        map.put("value", "");
        return map;
    }

    public static String getDescription(String names){
        String desc = null;
        for (ExamTypeEnum e:ExamTypeEnum.values() ) {
            if (e.name().equals(names.toUpperCase())){
                desc = e.description;
                break;
            }
        }
        return desc;
    }
}
